package cn.lanqiao.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import cn.lanqiao.entity.ApiResult;
import cn.lanqiao.entity.Fill_error;
import cn.lanqiao.entity.Judge_error;
import cn.lanqiao.util.ApiResultHandler;

@RestController
//跨域
@CrossOrigin(origins="*",maxAge=3600)
public class Judge_errorController {
	 @Autowired
	 private cn.lanqiao.service.Judge_errorService errorservice;
	 @GetMapping("/errorjudge/{studentId}")
     public ApiResult findById(@PathVariable("studentId") Integer studentId) {
     List<Judge_error> res = errorservice.findById(studentId);
     if (!res.isEmpty()) {
         return ApiResultHandler.buildApiResult(200, "根据ID查询错题", res);
     } else {
         return ApiResultHandler.buildApiResult(400, "ID不存在", res);
     }
	 }
	 @DeleteMapping("/deletejudge/{questionId}")
	 	public Map<String,Object> delete(@PathVariable (value="questionId") Integer questionId){
	 		Map<String,Object>  map = new HashMap<String,Object>();
	 		int result = errorservice.deleteById(questionId);
	 		if(result>0) {
	 			map.put("status", 200);
	 			map.put("statusText", "删除成功");
	 		}else{
	 			map.put("status", 0);
	 			map.put("statusText", "删除失败");
	 		}
	 		return map;
	 	}
	 @PostMapping("/insert/judge")
	    public ApiResult add(@RequestBody Judge_error judge) {
	        int res = errorservice.add(judge);
	        if (res == 0) {
	            return ApiResultHandler.buildApiResult(400,"成绩添加失败",res);
	        }else {
	            return ApiResultHandler.buildApiResult(200,"成绩添加成功",res);
	        }
	    }
}
